package com.sl.water.dto;

import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
import java.util.Optional;

/**
 * @description:
 * @author: duan
 * @time: 2025-06-12 17:29
 */
@Data
public class ForecastSchemeDTO implements Serializable {
    private Long id;
    private ReservoirResult reservoirResult;
    private RiverSectionAnalysisDTO riverSectionAnalysisDTO;

    public double getReservoirMaxWaterLevelOrDefault() {
        if (Objects.isNull(reservoirResult)) {
            return 0.0;
        }
        return Optional.ofNullable(reservoirResult.getMaxWaterLevel()).orElse(0.0);

    }

    public List<Double> getReservoirWaterLevelProcess() {
        if (Objects.isNull(reservoirResult)) {
            return new ArrayList<>();
        }
        return Optional.ofNullable(reservoirResult.getWaterLevelProcess()).orElse(new ArrayList<>());

    }

    public List<String> getReservoirTimeSeries() {
        if (Objects.isNull(reservoirResult)) {
            return new ArrayList<>();
        }
        return Optional.ofNullable(reservoirResult.getTimeSeries()).orElse(new ArrayList<>());
    }


    public double getRiverSectionAnalysisDTOMaxFlowOrDefault() {
        if (Objects.isNull(riverSectionAnalysisDTO)) {
            return 0.0;
        }
        return Optional.ofNullable(riverSectionAnalysisDTO.getMaxFlow()).orElse(0.0);

    }

    public double getRiverSectionAnalysisDTOMaxWaterLevel() {
        if (Objects.isNull(riverSectionAnalysisDTO)) {
            return 0.0;
        }
        return Optional.ofNullable(riverSectionAnalysisDTO.getMaxWaterLevel()).orElse(0.0);

    }

    public List<Double> getRiverSectionAnalysisDTOWaterLevelProcess() {
        if (Objects.isNull(riverSectionAnalysisDTO)) {
            return new ArrayList<>();
        }
        return Optional.ofNullable(riverSectionAnalysisDTO.getWaterLevelProcess()).orElse(new ArrayList<>());

    }

    public List<String> getRiverSectionAnalysisDTOTmProcess() {
        if (Objects.isNull(riverSectionAnalysisDTO)) {
            return new ArrayList<>();
        }
        return Optional.ofNullable(riverSectionAnalysisDTO.getTmProcess()).orElse(new ArrayList<>());

    }

    @Data
    @Builder
    @NoArgsConstructor
    @AllArgsConstructor
    static class ReservoirResult implements Serializable {

        private Double maxWaterLevel;
        private List<Double> waterLevelProcess;
        private List<String> timeSeries;
    }

    @Data
    @Builder
    @NoArgsConstructor
    @AllArgsConstructor
    static class RiverSectionAnalysisDTO implements Serializable {
        private Double maxFlow;
        private List<Double> waterLevelProcess;
        private List<String> tmProcess;
        private Double maxWaterLevel;
    }
}
